<?php
class CoachorderModel extends Model {

	protected $tableName = 'coach_order';
	protected $fields = array(
			0=>'oid',
			1=>'title',
			2=>'content',
			3=>'coach_id',
			4=>'people_limit',
			5=>'peoplo_current',
			6=>"start_time",
			7=>"status",
			
	);

	public function getCoathorderList($limit = 20, $map = array(),$order = "oid DESC"){
		// 添加用户表的查询，用于关联查询
		
		if (isset ( $_POST )) {
			$_POST ['oid'] && $map ['oid'] = intval ( $_POST ['oid'] );
			$_POST ['title'] && $map ['title'] = t ( $_POST ['title'] );
			$_POST ['content'] && $map ['content'] = t ( $_POST ['content'] );
			$_POST ['coach_id'] && $map ['coach_id'] = t ( $_POST ['coach_id'] );
			$_POST ['people_limit'] && $map ['people_limit'] = t ( $_POST ['people_limit'] );
			$_POST ['start_time'] && $map ['start_time'] = t ( $_POST ['start_time'] );
			$_POST ['status'] && $map ['status'] = t ( $_POST ['status'] );
			
			// 注册时间判断，apply_time为数组格式
			if (! empty ( $_POST ['start_time'] )) {
				if (! empty ( $_POST ['start_time'] [0] ) && ! empty ( $_POST ['start_time'] [1] )) {
					// 时间区间条件
					$map ['apply_time'] = array (
							'BETWEEN',
							array (
									strtotime ( $_POST ['start_time'] [0] ),
									strtotime ( $_POST ['start_time'] [1] )
							)
					);
				} else if (! empty ( $_POST ['start_time'] [0] )) {
					// 时间大于条件
					$map ['start_time'] = array (
							'GT',
							strtotime ( $_POST ['start_time'] [0] )
					);
				} elseif (! empty ( $_POST ['start_time'] [1] )) {
					// 时间小于条件
					$map ['start_time'] = array (
							'LT',
							strtotime ( $_POST ['start_time'] [1] )
					);
				}
			}

		}	
		// 查询数据
		$list = $this->where ( $map )->order ( $order )->findPage ( $limit );
		
		return $list;
	
	}
}
